// 封装axios
import axios from 'axios'

const baseURLObj = {
    "development": "/api",  //开发模式前缀用/api
    "production": 'http://47.94.148.165:3001/api' //生产模式下的前缀
}
console.log(process.env.NODE_ENV)  //获取到当前是开发模式还是生成模式
const instance = axios.create({
    baseURL: baseURLObj[process.env.NODE_ENV],
    timeout: 5000
})
instance.interceptors.request.use(config => {
    let token = localStorage.getItem("token");
    if (token) {
        config.headers.token = token;
    }
    return config;
}, (err) => {
    return Promise.reject(err)
})

instance.interceptors.response.use(res => {
    return res;
}, (err) => {
    return Promise.reject(err)
})

export default instance